package com.ruoyi.web.controller.applet;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.applet.domain.MiniIcon;
import com.ruoyi.applet.service.IMiniIconService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图标Controller
 *
 * @author liucan
 * @date 2024-03-25
 */
@RestController
@RequestMapping("/applet/icon")
public class MiniIconController extends BaseController {
    @Resource
    private IMiniIconService miniIconService;

    @Resource
    private MiniLeagueController miniLeagueController;

    /**
     * 查询图标列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MiniIcon miniIcon, HttpServletRequest request) {
        startPage();
        miniIcon.setToApplet(miniLeagueController.toApplet(request));
        List<MiniIcon> list = miniIconService.selectMiniIconList(miniIcon);
        return getDataTable(list,null);
    }

    /**
     * 新增图标
     */
    @Log(title = "图标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniIcon miniIcon, HttpServletRequest request) {
        miniIcon.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniIconService.insertMiniIcon(miniIcon));
    }

    /**
     * 修改图标
     */
    @Log(title = "图标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniIcon miniIcon, HttpServletRequest request) {
        miniIcon.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniIconService.updateMiniIcon(miniIcon));
    }

    /**
     * 删除图标
     */
    @Log(title = "图标", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(miniIconService.deleteMiniIconByIds(ids));
    }


    /**
     * 导出图标列表
     */
    @Log(title = "图标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniIcon miniIcon) {
        List<MiniIcon> list = miniIconService.selectMiniIconList(miniIcon);
        ExcelUtil<MiniIcon> util = new ExcelUtil<MiniIcon>(MiniIcon.class);
        util.exportExcel(response, list, "图标数据");
    }

    /**
     * 获取图标详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(miniIconService.selectMiniIconById(id));
    }

}
